package com.demo.controller;


import com.demo.service.ModVOService;
import com.demo.vo.Module;
import com.demo.vo.ModVOSeacherInfo;
import com.demo.vo.Pro;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping
public class ModVOController {

    @Autowired
    ModVOService modVOService;

    /**
     * 分页查看模块表格
     * @param info
     * @return list
     */
    @RequestMapping("getModList")
    @ResponseBody
    public HashMap getModList(ModVOSeacherInfo info){
        HashMap map=new HashMap();
        List<Module> modList=modVOService.getModList(info);
        int totalCount=modVOService.getModCount(info);
        map.put("code",0);
        map.put("msg","");
        map.put("count",totalCount);
        map.put("data",modList);
        return map;
    }

    @RequestMapping("addMod")
    @ResponseBody
    public HashMap addMod(Module module){
        HashMap map=new HashMap();
        int res=modVOService.addMod(module);
        if(res>0){
            map.put("code",0);
            map.put("msg","添加成功");
        }else{
            map.put("code",-1);
            map.put("code","添加失败");
        }
        return map;
    }

    @RequestMapping("getAllProjectList")
    @ResponseBody
    public List<Pro> getAllProjectList(){
        List<Pro> projectList=modVOService.getAllProjectList();
        return projectList;
    }

    @RequestMapping("deleteMod")
    @ResponseBody
    public HashMap deleteMod(String modId){
        HashMap map=new HashMap();
        int res=modVOService.deleteMod(modId);
        if(res>0){
            map.put("code",0);
            map.put("msg","删除成功");
        }else{
            map.put("code",-1);
            map.put("code","删除失败");
        }
        return map;
    }

    @RequestMapping("updateMod")
    @ResponseBody
    public HashMap updateMod(Module module){
        HashMap map=new HashMap();
        int res=modVOService.updateMod(module);
        if(res>0){
            map.put("code",0);
            map.put("msg","修改成功");
        }else{
            map.put("code",-1);
            map.put("code","修改失败");
        }
        return map;
    }
}
